package com.cjkj.hospital.controller;

import com.cjkj.common.annotation.Log;
import com.cjkj.common.annotation.RepeatSubmit;
import com.cjkj.common.core.controller.BaseController;
import com.cjkj.common.core.domain.AjaxResult;
import com.cjkj.common.core.page.TableDataInfo;
import com.cjkj.common.enums.BusinessType;
import com.cjkj.hospital.domain.THospitalDept;
import com.cjkj.hospital.domain.dto.HospitalDeptReq;
import com.cjkj.hospital.domain.vo.HospitalDeptVo;
import com.cjkj.hospital.service.ITHospitalDeptService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * 医院科室信息Controller
 * 
 * @author cjkj
 * @date 2024-08-28
 */
@Validated
@RestController
@RequestMapping("/hospital/dept")
public class THospitalDeptController extends BaseController
{
    @Resource
    private ITHospitalDeptService tHospitalDeptService;

    /**
     * 查询医院科室信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:dept:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalDeptReq req)
    {
        startPage();
        List<HospitalDeptVo> list = tHospitalDeptService.selectTHospitalDeptList(req);
        return getDataTable(list);
    }

    /**
     * 新增医院科室信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:dept:add')")
    @Log(title = "医院科室信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Valid THospitalDept tHospitalDept)
    {
        return toAjax(tHospitalDeptService.insertTHospitalDept(tHospitalDept));
    }

    /**
     * 获取医院科室信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:dept:query')")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") String deptId)
    {
        return success(tHospitalDeptService.selectTHospitalDeptByDeptId(deptId));
    }

    /**
     * 修改医院科室信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:dept:edit')")
    @Log(title = "医院科室信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit(interval = 1000, message = "请求过于频繁！")
    @PutMapping
    public AjaxResult edit(@RequestBody THospitalDept tHospitalDept)
    {
        return toAjax(tHospitalDeptService.updateTHospitalDept(tHospitalDept));
    }

    /**
     * 删除医院科室信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:dept:remove')")
    @Log(title = "医院科室信息", businessType = BusinessType.DELETE)
    @RepeatSubmit(interval = 1000, message = "请求过于频繁！")
	@DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable String[] deptIds)
    {
        return success(tHospitalDeptService.deleteTHospitalDeptByDeptIds(deptIds));
    }

    /**
     * 获取下拉框选项
     * @return
     */
    @GetMapping("getDeptOptionData")
    public AjaxResult getDeptOptionData(@NotBlank(message = "医院id不能为空！") String hospitalId){
        return success(tHospitalDeptService.getDeptOptionData(hospitalId));
    }
}
